﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using SecurityBLL;
using System.Text;
using System.Collections;

/// <summary>
/// Menu 的摘要说明
/// </summary>
public class Menu
{
    private CaiDanJieDianBLL caiDanJieDianBLL = new CaiDanJieDianBLL();
	public Menu()
	{
		//
		// TODO: 在此处添加构造函数逻辑
		//
	}
    public string PaintingMenu(Hashtable quanXianTable, string url)      //根据权限返回菜单字符串
    {

        return Painting_logic_Menu(quanXianTable, url);

    }
    private DataTable GetMenuTable()                        
    {

        DataTable menutable = new DataTable();
        menutable = caiDanJieDianBLL.GetCaiDanJieDian();
        return menutable;
    }

    /// <summary>
    /// 依据权限查询菜单节点
    /// </summary>
    /// <returns></returns>
    private string Painting_logic_Menu(Hashtable quanXianTable, string url)
    {

        DataTable getMenuTable = GetMenuTable();
        string sqlStr = "";//跟菜单节点的条件
        string sqlStr2 = "";//第二级菜单节点的条件
        string rightStr = "";//菜单节点权限
        StringBuilder menuText = new StringBuilder();

        menuText.Append("<div class='mainmenu'> ");
        menuText.Append("<div class='onemainmenu' id=0>" +
                              "<div class='menuTexthome'>Home</div>" +
                        "</div>");

        if (getMenuTable.Rows.Count > 0 && getMenuTable != null)
        {

            sqlStr = "CD_Pid = -1 ";

            DataRow[] yJCaiDanRows = getMenuTable.Select(sqlStr, "CD_PaiXuWeiZhi");     //获得一级菜单

            Hashtable right = quanXianTable;
            for (int index = 0; index < yJCaiDanRows.Length; index++)                   //处理一级菜单
            {
                menuText.Append(" <div class='onemainmenu' id=" + index + ">" +              //生成主菜单
                                      "<div class='tri1'></div>" +
                                      "<div class='menuText'>" + yJCaiDanRows[index]["CD_MingCheng"].ToString().Trim() + "</div>" +
                                 "</div>");


                sqlStr2 = "CD_PID=" + yJCaiDanRows[index]["CD_ID"].ToString().Trim();
                DataRow[] eJCaiDanRows = getMenuTable.Select(sqlStr2, "CD_PaiXuWeiZhi"); //获得二级菜单

                menuText.Append("<div class='submenu'>");                                //子菜单
                for (int index2 = 0; index2 < eJCaiDanRows.Length; index2++)             //处理二级菜单
                {

                    rightStr = eJCaiDanRows[index2]["CD_QuanXian"].ToString().Trim();

                    //rightStr = yJCaiDanRows[index]["CD_QuanXian"].ToString().Trim();

                    if (right != null)
                    {
                        if (right.Contains(rightStr))
                        {
                            string urlstr = "";
                            urlstr = "/" + url + eJCaiDanRows[index2]["CD_LianJieLuJing"].ToString().Trim();
                            menuText.Append("<div class='onesubmenu' nurl = " + urlstr + ">" +
                                                 "<div class='report'></div>" +
                                                 "<div class='menuText'>" + eJCaiDanRows[index2]["CD_MingCheng"].ToString().Trim() + "</div>");
                            menuText.Append("</div>");
                            //      menuText.Append(" <a href='/ERP_WEB/WebBrowser/WebPage/XiaoShouShenPi/XiaoShouShenPiLiuLan.aspx' title=''>供应商业务联系人信息</a> ");
                        }
                    }


                }
                menuText.Append("</div>");               //子菜单结束
            }
        }
        menuText.Append("  	</div> ");                   //菜单结束

        return menuText.ToString();
    }
}